package com.tbit.uqbike.push.util;


/**
 * @author Kang
 * @createTime 2018年10月15日 下午3:02:27
 * @description 终端 工具类
 */
public class TerminalUtils {

    public static boolean getLockState(String str) {
        //将字符转化为十进制
        Integer i = Integer.valueOf(str);
        byte b = 0x01;
        b = (byte) (i & b);
        if (b == 1) {
            return true; //借车状态
        } else {
            return false;//锁车状态
        }
    }

    public static boolean getPowerState(String str) {
        //将字符转化为十进制
        Integer i = Integer.valueOf(str);
        byte b = 0x08;
        b = (byte) (i & b);
        if (b == 8) {
            return true; //供电状态
        } else {
            return false;//断电状态
        }
    }

    public static byte[] HexStringToBytesEndMask(String hex, char ch) {
        String str = hex;
        if (str.length() % 2 == 1)
            str += ch;
        return HexStringToBytesEndMask(str, ch, str.length() / 2);
    }

    public static byte[] HexStringToBytesEndMask(String hex, char ch, int len) {
        byte[] data = new byte[len];
        String str = hex;
        if (str.length() % 2 == 1)
            str += ch;
        byte dfByte = (byte) Integer.parseInt(new String(new char[]{ch, ch}), 16);
        int strlen = str.length() / 2;
        for (int i = 0; i < len; i++) {
            if (i < strlen) {
                data[i] = (byte) Integer.parseInt(str.substring(i << 1, (i << 1) + 2), 16);
                ;
            } else {
                data[i] = dfByte;
            }
        }
        return data;
    }

    /**
     * 获取开关变量
     *
     * @param i
     * @param index
     * @return
     */
    public static boolean testBit(int i, int index) {
        int mask = 1 << index;
        return (i & mask) != 0;
    }

    public static void main(String[] args) {
        byte[] bs = HexStringToBytesEndMask("B237", '3');
        System.out.println(bs.length);
    }

}
